with open("Walden.txt","r+",encoding="utf-8") as f:
#将文件读入1个str并去除特殊符号
    txt =f.read()
    for i in ",.\"?!-/":
     txt =txt.replace(i ,"")

def tonji(x):
#用split方法进行字符串拆分并导入列表
    readlist = x.split()
#创建字典，没有就直接新增，有就vlaue加1
    dict1={}
    for i in readlist:
        if i in dict1:
            dict1[i]+=1
        else:
            dict1[i]=1
#返回 dict1
    return dict1
print(tonji(txt))
